package linwen.wang.redis.jedis;

import org.junit.Test;
import redis.clients.jedis.Jedis;

/**
 * @ClassName JedisSet
 * @Description
 * @Author lin
 * @Date 2022/3/2 下午9:39
 * @Version V1.0
 */
public class JedisSet {

    // set
    @Test
    public void test(){
        Jedis jedis = new Jedis();
        jedis.flushAll();
        //添加一个或多个数据
        jedis.sadd("s1", "a","b","c");
        jedis.sadd("s1", "d");

        //返回集合中所有元素
        System.out.println(jedis.smembers("s1"));

        //成员个数
        System.out.println(jedis.scard("s1"));

        //求交集，并集，差集
        jedis.sadd("s2", "c","d","e","f");

        System.out.println(jedis.sinter("s1","s2"));

        System.out.println(jedis.sunion("s1","s2"));

        System.out.println(jedis.sdiff("s1","s2"));

        //判断是否是成员
        System.out.println(jedis.sismember("s1", "c"));

        //移除一个或者多个元素
        jedis.srem("s1", "b","c");
        System.out.println(jedis.smembers("s1"));

        jedis.close();
    }

}
